package neusoft.yuejian_11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.yuejian_11.activity.TrainDetailActivity;
import neusoft.yuejian_11.base.BaseListAdapter;
import neusoft.yuejian_11.bean.TrainBean;
import neusoft.yuejian_11.R;
import neusoft.yuejian_11.viewHolder.TrainitemViewHolder;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

/**
 * Created by neusoft on 2017/9/29.
 */

public class TrainListAdapter extends BaseListAdapter {
    public TrainListAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_train_list, parent, false);
        TrainitemViewHolder viewHolder = new TrainitemViewHolder(itemView);
        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        final TrainBean train = (TrainBean) data.get(position);
        TrainitemViewHolder viewHolder = (TrainitemViewHolder) holder;

        final int clubId = train.getC_id();
        final int type = train.getT_type();
        final int trainId = train.getT_id();
        final String trainName = train.getT_name();
        final String trainPhone = train.getT_phone();

        viewHolder.trainNameView.setText(trainName);

        final String trainPicture = BASE_URI+"trainpicture/"+train.getT_picture();
        Picasso.with(context)
                .load(trainPicture)
                .placeholder(R.drawable.ic_club)
                .error(R.drawable.ic_noclub)
                .into(viewHolder.imageView);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的Activity--培训详情
                Intent intent = new Intent(context, TrainDetailActivity.class);
                intent.putExtra("t_name",trainName);
                intent.putExtra("t_picture",trainPicture);
                intent.putExtra("t_phone",trainPhone);
                intent.putExtra("t_type",type);
                intent.putExtra("t_id",trainId);
                intent.putExtra("c_id",clubId);
                context.startActivity(intent);
            }
        });

    }

}
